import logging
from redis import StrictRedis


class AppConfig(object):
    """配置类"""
    DEBUG = True

    # 配置秘钥
    SECRET_KEY = "jg-we-j'-wq-j9340ut883905_-24423F"

    # 配置MySQL数据库
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information_flash"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 配置Redis数据库
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_DB = 0

    # 配置通过配置app,来配置Session的config
    # 配置存储类型
    SESSION_TYPE = "redis"
    # 指定存储的数据库位置
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
    # 存储是否使用签名
    SESSION_USE_SIGNER = True
    # SESSION_PERMANENT=True才能通过 app 设置PERMANENT_SESSION_LIFETIME来控制有效时间
    PERMANENT_SESSION_LIFETIME = 60*60*24


class DevelopmentConfig(AppConfig):
    """配置开发时的配置信息"""
    LOGGING_LEVEL = logging.DEBUG


class UnittestConfig(AppConfig):
    """配置测试时的配置信息"""
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information_flash"
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_DB = 0
    LOGGING_LEVEL = logging.DEBUG


class ProductionConfig(AppConfig):
    """配置上线时的配置信息"""
    DEBUG = False
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information_flash"
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_DB = 0
    LOGGING_LEVEL = logging.ERROR


conf_dict = {
    "dev": DevelopmentConfig,
    "test": UnittestConfig,
    "pro": ProductionConfig
}
